home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume91 / utilitys / names_11 / part01 / names.c next >
C/C++ Source or Header  |  1991-05-18  |  2KB  |  80 lines

  1. /*
  2. Names v1.1 by Russell Wallace 29 July 1989
  3. Program to generate random names
  4. Useful for generating names for stuff like computer games and so on when you
  5. can't be bothered thinking them up yourself. At the moment it avoids runs of
  6. more than 2 vowels or 2 consonants in a row and generates words of between
  7. 3 and 10 letters ... many of the names are unusable, select the usable ones.
  8. I decided this was easier than trying to improve the generation process.
  9. */
  10.  
  11. #define videornd  (*((unsigned *)0xdff006))
  12.  
  13. long RangeRand ();
  14.  
  15. char buffer[11];
  16.  
  17. main (argc,argv)
  18. char **argv;
  19. {
  20.     int i,j,l,NAMES=50;
  21.     char c,c1,c2;
  22.     if (argc>1)
  23.     {
  24.     if (!strcmp (argv[1],"?"))
  25.     {
  26.         printf ("Names v1.1 by Russell Wallace 29 July 1989\n\
  27. Generates random names for fantasy games etc.\n\
  28. Usage: NAMES [number of names to generate]\n");
  29.         return;
  30.     }
  31.     NAMES=atoi (argv[1]);
  32.     }
  33.     for (j=0;j<NAMES;j++)
  34.     {
  35.     l=rnd (7)+3;
  36.     for (i=0;i<l;i++)
  37.     {
  38.         if (i<=1)
  39.         buffer[i]=rnd (26)+'a';
  40.         else
  41.         {
  42.         c1=buffer[i-1];
  43.         c2=buffer[i-2];
  44.         do
  45.         {
  46.             if (rnd (50)==0)
  47.             {
  48.             if (rnd (2))
  49.                 c='-';
  50.             else
  51.                 c='\'';
  52.             }
  53.             else
  54.             c=rnd (26)+'a';
  55.         }
  56.         while (
  57.             (!isvowel (c1) && !isvowel (c2) && !isvowel (c)) ||
  58.             (isvowel (c1) && isvowel (c2) && isvowel (c))
  59.               );
  60.         buffer[i]=c;
  61.         }
  62.     }
  63.     buffer[i]=0;
  64.     printf ("%s\n",buffer);
  65.     }
  66. }
  67.  
  68. int isvowel (c)
  69. char c;
  70. {
  71.     return (c=='a' || c=='e' || c=='i' || c=='o' || c=='u');
  72. }
  73.  
  74. rnd (x)
  75. {
  76.     RangeRand ((long)videornd);
  77.     return RangeRand ((long)x);
  78. }
  79.  
  80.